<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>数据分析</title>
<link rel="stylesheet" type="text/css" href="./static/css/easyui.css">
<link rel="stylesheet" type="text/css" href="./static/css/icon.css">
<link rel="stylesheet" type="text/css" href="./static/css/demo.css">
<style type="text/css">
	ul li{
		list-style-type: none;
	}
</style>
<script type="text/javascript" src="./static/js/jquery.min.js"></script>
<script type="text/javascript" src="./static/js/jquery.easyui.min.js"></script>
</head>
<body>
	<h2>数据分析</h2>
	<input class="easyui-combobox" id="tableName" name="tableNameX" value="">
	<div style="margin:20px 0;"></div>
	<div id="columnValueDiffTotalPanel" class="easyui-panel" title="未刷新更新时间" style="width:100%;">
		<ul>
			<li>
				<ul>
					<li>累计数量:<span id="diffIdCount"></span></li>
					<li>记录主键:&nbsp;&nbsp;<span id="diffIds"></span></li>
				</ul>
			</li>
		</ul>
	</div>
	<div style="margin:20px 0;"></div>
	<div id="columnValueDiffPanel" class="easyui-panel" title="如下字段有修改，却没有刷新更新时间" style="width:100%;">
		<ol>
		</ol>
	</div>	
	<div style="margin:20px 0;"></div>
	<div id="columnNameDiffPanel" class="easyui-panel" title="表结构差异" style="width:100%;"></div>

	<div id="columnValueDiffLi" style="display:none;">
		<ol>
			<li>
				<ul>
					<li>字段名:<span title="columnName" style="color:red;"></span></li>
					<li>记录数量:<span title="recordCount"></span></li>
					<li>记录主键:&nbsp;&nbsp;<span title="recordIDs"></span></li>
				</ul>
			</li>
		</ol>
	</div>
	<div id="columnNameDiff" style="display:none;">
		<p>ERP独有的字段</p>
		<ul>
			<li>字段个数:<span title="erpOnlyCount"></span></li>
			<li>字段名称:&nbsp;&nbsp;<span title="erpOnlyColumnNames"></span></li>
		</ul>
		<hr>
		<p>DW独有的字段</p>
		<ul>
			<li>字段个数:<span title="dwOnlyCount"></span></li>
			<li>字段名称:&nbsp;&nbsp;<span title="dwOnlyColumnNames"></span></li>
		</ul>
		<hr>
		<p>共有的字段</p>
		<ul>
			<li>字段个数:<span title="bothErpAndDwCount"></span></li>
			<li>字段名称:&nbsp;&nbsp;<span title="bothErpAndDwColumnNames"></span></li>
		</ul>		
	</div>
	<script type="text/javascript">
		$(function(){
			console.info("加载数据分析页面完成");
			$('#tableName').combobox({
				//readonly:true, 
				mode:'remote',
				method:'get',
			    url:getRootPath()+'/getComboOfTableName',
			    onSelect:function(record){
			    	if (!record || !record.value) {return;};
			    	$.ajax({
			    		url: getRootPath()+'/dataAnalysis/'+record.value,
			    		type: 'GET',
			    		dataType: 'json'
			    	})
			    	.done(function(data) {
			    		$("#columnValueDiffPanel ol").html('');
			    		$("#columnValueDiffTotalPanel span").html('');
			    		$("#columnNameDiffPanel").html('');

			    		if (data) {
			    			$("#columnNameDiff span").html('');
			    			$("#columnNameDiff span[title='erpOnlyCount']").html(data.erpOnlyCount||0);
			    			if (data.erpOnly) {
			    				$("#columnNameDiff span[title='erpOnlyColumnNames']").html(data.erpOnly.join(','));
			    			};			    			
			    			$("#columnNameDiff span[title='dwOnlyCount']").html(data.dwOnlyCount||0);
			    			if (data.dwOnly) {
			    				$("#columnNameDiff span[title='dwOnlyColumnNames']").html(data.dwOnly.join(','));
			    			};	
			    			$("#columnNameDiff span[title='bothErpAndDwCount']").html(data.bothErpAndDwCount||0);
			    			if (data.bothErpAndDw) {
			    				$("#columnNameDiff span[title='bothErpAndDwColumnNames']").html(data.bothErpAndDw.join(','));
			    			};
			    			$("#columnNameDiffPanel").html('').html($("#columnNameDiff").children().clone());	
			    			$("#columnNameDiff span").html('');

			    			$("#columnValueDiffTotalPanel #diffIdCount").html(data.diffIdCount||0);
			    			if (data.diffIds) {
			    				$("#columnValueDiffTotalPanel #diffIds").html(data.diffIds.join(','));
			    			}

			    			if (data.diffMap) {
			    				for(var key in data.diffMap){
				    				$("#columnValueDiffLi span").html('');
			    					$("#columnValueDiffLi span[title='columnName']").html(key);
			    					$("#columnValueDiffLi span[title='recordCount']").html(data.diffMap[key].length);
			    					$("#columnValueDiffLi span[title='recordIDs']").html(data.diffMap[key].join(','));
			    					$("#columnValueDiffPanel ol").append($("#columnValueDiffLi ol").children().clone());
			    				} 
			    				$("#columnValueDiffLi span").html('');
			    			}
			    		};
			    		console.log("success");
			    	})
			    	.fail(function() {
			    		console.log("error");
			    	})
			    	.always(function() {
			    		console.log("complete");
			    	});
			    	
			    }
			});
		});


		function submitForm(){
			$.messager.progress();	// display the progress bar
			$('#dataCollectionForm').form('submit', {
				url: getRootPath()+'/dataCollection',
				onSubmit: function(){
					var isValid = $(this).form('enableValidation').form('validate');
					if (!isValid){
						$.messager.progress('close');	// hide progress bar while the form is invalid
					}
					return isValid;	// return false will stop the form submission
				},
				success: function(){
					$.messager.progress('close');	// hide progress bar while submit successfully
				}
			});			
		}
		function clearForm(){
			$('#dataCollectionForm').form('clear');
		}

		//js获取项目根路径，如： http://localhost:8083/uimcardprj
		function getRootPath(){
		    //获取当前网址，如： http://localhost:8083/uimcardprj/share/meun.jsp
		    var curWwwPath=window.document.location.href;
		    //获取主机地址之后的目录，如： uimcardprj/share/meun.jsp
		    var pathName=window.document.location.pathname;
		    var pos=curWwwPath.indexOf(pathName);
		    //获取主机地址，如： http://localhost:8083
		    var localhostPaht=curWwwPath.substring(0,pos);
		    //获取带"/"的项目名，如：/uimcardprj
		    var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);
		    return(localhostPaht+projectName);
		}
	</script>	
</body>
</html>